package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPageVO;
import com.sky.vo.OrderStatisticsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 订单分页
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result page(OrdersPageQueryDTO dto){

        PageResult pageResult = orderService.historyOrders(dto);
        return Result.success(pageResult);
    }

    /**
     * 查询订单详细信息
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result orderInfo(@PathVariable("id") String id){

        OrderPageVO vo = orderService.orderInfo(Long.parseLong(id));
        return Result.success(vo);
    }

    /**
     * 商户接单
     * @param id
     * @return
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody String id){

        orderService.takeOrder(Long.parseLong(id));
        return Result.success();
    }

    /**
     * 商户拒单
     * @param dto
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){

        orderService.rejection(dto);
        return Result.success();
    }

    /**
     * 商户派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") String id){

        orderService.delivery(Long.parseLong(id));
        return Result.success();
    }

    /**
     * 订单完成
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") String id){

        orderService.complete(Long.parseLong(id));
        return Result.success();
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    public Result statistics(){

        OrderStatisticsVO vo = orderService.statistics();
        return Result.success(vo);
    }
}
